﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRMSalesManagement.Manage.FrontPageManagement
{
    public partial class ProductsList : System.Web.UI.Page
    {
        private static string newsType = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int pageNum = 1;
                if (Request.QueryString["page"] != null)
                {
                    pageNum = int.Parse(Request.QueryString["page"]);
                }
                int total = 0;
                var columnDb = CRM.Business.Product.PageListProducts(out total, pageNum, this.DataPage1.ShowRecordCount);
                this.DataPage1.TotalRecordCount = total;
                this.DataPage1.ShowPageNumberCount = pageNum;
                if (columnDb != null)
                {                   
                    this.gvProductsList.DataSource = columnDb;
                    this.gvProductsList.DataBind();
                }

                #region 控制分页控件
                CRM.Business.ShowPageDispaly.PageDispaly(this.DataPage1, pageNum, total);
                #endregion
            }
        }

        protected void gvNewsList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = Convert.ToInt32(gvProductsList.DataKeys[e.RowIndex].Value);
            var news = CRM.Business.Product.GetNewById(id);
            if (news != null)
            {
                bool result = CRM.Business.Product.DeleteProduct(news);
                if (result)
                {
                    this.lblResult.Text = "*删除成功";
                }
                else
                {
                    this.lblResult.Text = "*删除失败";
                }
                Response.Redirect("/Manage/FrontPageManagement/ProductsList.aspx");
                //GridViewBinding();
            }
        }

        protected void gvNewsList_RowEditing(object sender, GridViewEditEventArgs e)
        {            
            Session["productid"] = Convert.ToInt32(gvProductsList.DataKeys[e.NewEditIndex].Value);
            Response.Redirect("ProductModify.aspx");
        }
    }
}